//
//  YDBillDetailsController.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2018/1/22.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDBillDetailsController.h"
#import "YDFundDetailsModel.h"



@interface YDBillDetailsController ()
//流水号
@property (nonatomic , weak) UILabel *serialNumberLabel;
@property (nonatomic , weak) UILabel *serialNumber;
//类型
@property (nonatomic , weak) UILabel *typeLabel;
@property (nonatomic , weak) UILabel *type;
//收入
@property (nonatomic , weak) UILabel *incomeLabel;
@property (nonatomic , weak) UILabel *income;
//时间
@property (nonatomic , weak) UILabel *timeLabel;
@property (nonatomic , weak) UILabel *time;
//余额
@property (nonatomic , weak) UILabel *balanceLabel;
@property (nonatomic , weak) UILabel *balance;
//备注
@property (nonatomic , weak) UILabel *remarksLabel;
@property (nonatomic , weak) UILabel *remarks;

@end

@implementation YDBillDetailsController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"账单详情";
    [self addChildLabels];
    
}


-(void)setFundDict:(NSDictionary *)fundDict
{
    _fundDict = fundDict;
    
    //可用金额
    NSString *availableBalance = [NSString stringWithFormat:@"%@",fundDict[@"availableBalance"]];
    
    if ([availableBalance floatValue] == 0) {
        self.balance.text = @"0.00";
    }else{
        self.balance.text = [NSString countNumAndChangeformat:[availableBalance pz_stringNumberByMultiplyingBy:@"1"]];
        
    }
}

-(void)setModel:(YDFundDetailsModel *)model
{
    _model = model;
    //流水号
    self.serialNumber.text = model.flowNo;
    //类型
    self.type.text = model.flowText;
    
    //收入
    self.income.text = [NSString stringWithFormat:@"%@元" , model.fundAccunt];
    if ([model.amount floatValue] > 0) {
        self.income.textColor = [UIColor colorWithHexString:paleRed];
    }else{
        self.income.textColor = [UIColor colorWithHexString:leafyGreen];
    }
    
    //时间
    self.time.text = [NSString stringWithFormat:@"%@ %@" , model.year , model.hour];
    
    if (model.stockCode.length && model.stockName.length) {
        //备注
        self.remarks.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"%@" , model.stockCode] changeColor:[UIColor colorWithHexString:dark] changeFont:[UIFont systemFontOfSize:font12ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@ %@" , model.stockName , model.stockCode]];
    }else{
        self.remarks.text = @"";
    }
    
    if (model.paymentType.length) {
        self.remarks.text = model.paymentType;
        self.remarksLabel.text = @"充值方式:";
    }else
    {
        self.remarksLabel.text = @"备注:";
    }

}

-(void)addChildLabels
{
    [self serialNumberLabel];
    [self serialNumber];
    
    [self typeLabel];
    [self type];
    
    [self incomeLabel];
    [self income];
    
    [self timeLabel];
    [self time];
    
    [self balanceLabel];
    [self balance];

    [self remarksLabel];
    [self remarks];
}


/******************************/
//流水号
-(UILabel *)serialNumberLabel
{
    if (_serialNumberLabel == nil) {
        UILabel *serialNumberLabel = [[UILabel alloc] init];
        [self.view addSubview:serialNumberLabel];
        serialNumberLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        serialNumberLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        serialNumberLabel.textAlignment = NSTextAlignmentLeft;
        serialNumberLabel.text = @"流水号:";
        [serialNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.view).offset(rateX812(20));
            }else{
                make.top.equalTo(self.view).offset(rate750(20));
            }
        }];
        serialNumberLabel.adjustsFontSizeToFitWidth = YES;
        _serialNumberLabel = serialNumberLabel;
    }
    return _serialNumberLabel;
}
-(UILabel *)serialNumber
{
    if (_serialNumber == nil) {
        UILabel *serialNumber = [[UILabel alloc] init];
        [self.view addSubview:serialNumber];
        serialNumber.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        serialNumber.textColor = [UIColor colorWithHexString:dark];
        serialNumber.textAlignment = NSTextAlignmentRight;
//        serialNumber.text = @"20189288292282882";
        [serialNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-rate375(20));
            make.centerY.equalTo(self.serialNumberLabel);
        }];
        serialNumber.adjustsFontSizeToFitWidth = YES;
        _serialNumber = serialNumber;
    }
    return _serialNumber;
}

//类型
-(UILabel *)typeLabel
{
    if (_typeLabel == nil) {
        UILabel *typeLabel = [[UILabel alloc] init];
        [self.view addSubview:typeLabel];
        typeLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        typeLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        typeLabel.textAlignment = NSTextAlignmentLeft;
        typeLabel.text = @"类型:";
        [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.serialNumberLabel.mas_bottom).offset(rateX812(15));
            }else{
                make.top.equalTo(self.serialNumberLabel.mas_bottom).offset(rate750(15));
            }
        }];
        typeLabel.adjustsFontSizeToFitWidth = YES;
        _typeLabel = typeLabel;
    }
    return _typeLabel;
}
-(UILabel *)type
{
    if (_type == nil) {
        UILabel *type = [[UILabel alloc] init];
        [self.view addSubview:type];
        type.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        type.textColor = [UIColor colorWithHexString:dark];
        type.textAlignment = NSTextAlignmentRight;
//        type.text = @"T+1即时卖出";
        [type mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-rate375(20));
            make.centerY.equalTo(self.typeLabel);
        }];
        type.adjustsFontSizeToFitWidth = YES;
        _type = type;
    }
    return _type;
}

//收入
-(UILabel *)incomeLabel
{
    if (_incomeLabel == nil) {
        UILabel *incomeLabel = [[UILabel alloc] init];
        [self.view addSubview:incomeLabel];
        incomeLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        incomeLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        incomeLabel.textAlignment = NSTextAlignmentLeft;
        incomeLabel.text = @"收入:";
        [incomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.typeLabel.mas_bottom).offset(rateX812(15));
            }else{
                make.top.equalTo(self.typeLabel.mas_bottom).offset(rate750(15));
            }
        }];
        incomeLabel.adjustsFontSizeToFitWidth = YES;
        _incomeLabel = incomeLabel;
    }
    return _incomeLabel;
}
-(UILabel *)income
{
    if (_income == nil) {
        UILabel *income = [[UILabel alloc] init];
        [self.view addSubview:income];
        income.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        income.textColor = [UIColor colorWithHexString:dark];
        income.textAlignment = NSTextAlignmentRight;
//        income.text = @"+2000";
        [income mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-rate375(20));
            make.centerY.equalTo(self.incomeLabel);
        }];
        income.adjustsFontSizeToFitWidth = YES;
        _income = income;
    }
    return _income;
}

//
//时间
-(UILabel *)timeLabel
{
    if (_timeLabel == nil) {
        UILabel *timeLabel = [[UILabel alloc] init];
        [self.view addSubview:timeLabel];
        timeLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        timeLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        timeLabel.textAlignment = NSTextAlignmentLeft;
        timeLabel.text = @"时间:";
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.incomeLabel.mas_bottom).offset(rateX812(15));
            }else{
                make.top.equalTo(self.incomeLabel.mas_bottom).offset(rate750(15));
            }
        }];
        timeLabel.adjustsFontSizeToFitWidth = YES;
        _timeLabel = timeLabel;
    }
    return _timeLabel;
}
-(UILabel *)time
{
    if (_time == nil) {
        UILabel *time = [[UILabel alloc] init];
        [self.view addSubview:time];
        time.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        time.textColor = [UIColor colorWithHexString:dark];
        time.textAlignment = NSTextAlignmentRight;
//        time.text = @"+2000";
        [time mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-rate375(20));
            make.centerY.equalTo(self.timeLabel);
        }];
        time.adjustsFontSizeToFitWidth = YES;
        _time = time;
    }
    return _time;
}

//余额
-(UILabel *)balanceLabel
{
    if (_balanceLabel == nil) {
        UILabel *balanceLabel = [[UILabel alloc] init];
        [self.view addSubview:balanceLabel];
        balanceLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        balanceLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        balanceLabel.textAlignment = NSTextAlignmentLeft;
        balanceLabel.text = @"余额:";
        [balanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.timeLabel.mas_bottom).offset(rateX812(15));
            }else{
                make.top.equalTo(self.timeLabel.mas_bottom).offset(rate750(15));
            }
        }];
        balanceLabel.adjustsFontSizeToFitWidth = YES;
        _balanceLabel = balanceLabel;
    }
    return _balanceLabel;
}
-(UILabel *)balance
{
    if (_balance == nil) {
        UILabel *balance = [[UILabel alloc] init];
        [self.view addSubview:balance];
        balance.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        balance.textColor = [UIColor colorWithHexString:dark];
        balance.textAlignment = NSTextAlignmentRight;
//        balance.text = @"+2000";
        [balance mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-rate375(20));
            make.centerY.equalTo(self.balanceLabel);
        }];
        balance.adjustsFontSizeToFitWidth = YES;
        _balance = balance;
    }
    return _balance;
}


//备注
-(UILabel *)remarksLabel
{
    if (_remarksLabel == nil) {
        UILabel *remarksLabel = [[UILabel alloc] init];
        [self.view addSubview:remarksLabel];
        remarksLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        remarksLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        remarksLabel.textAlignment = NSTextAlignmentLeft;
        remarksLabel.text = @"备注:";
        [remarksLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.balanceLabel.mas_bottom).offset(rateX812(15));
            }else{
                make.top.equalTo(self.balanceLabel.mas_bottom).offset(rate750(15));
            }
        }];
        remarksLabel.adjustsFontSizeToFitWidth = YES;
        _remarksLabel = remarksLabel;
    }
    return _remarksLabel;
}
-(UILabel *)remarks
{
    if (_remarks == nil) {
        UILabel *remarks = [[UILabel alloc] init];
        [self.view addSubview:remarks];
        remarks.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        remarks.textColor = [UIColor colorWithHexString:dark];
        remarks.textAlignment = NSTextAlignmentRight;
//        remarks.text = @"平安银行";
        [remarks mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-rate375(20));
            make.centerY.equalTo(self.remarksLabel);
        }];
        _remarks.adjustsFontSizeToFitWidth = YES;
        _remarks = remarks;
    }
    return _remarks;
}


@end
